const path = require("path");
const webpack = require("webpack");

module.exports = {
  entry: "./src/",
  mode: "development",
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /(node_modules|bower_components)/,
        loader: "babel-loader",
        options: { presets: ["@babel/env"] },
      },
      {
        test: /\.css/,
        use: [
          {
            loader: "style-loader",
          },
          {
            loader: "css-loader",
          },
        ],
      },
      {
        test: /\.scss$/,
        use: [
          { loader: "style-loader" },
          {
            loader: "css-loader",
            options: {
              modules: {
                localIdentName: "[path][name]-[local]-[hash:5]",
              },
            },
          },
          { loader: "sass-loader" },
        ], //打包处理scss样式表的第三方loader
      },
    ],
  },
  resolve: { extensions: ["*", ".js", ".jsx"] },
  output: {
    path: path.resolve(__dirname, "dist/"),
    publicPath: "/dist/",
    filename: "bundle.js",
  },
  devServer: {
    contentBase: path.join(__dirname, "public/"), // 服务器打开路径
    host: "127.0.0.1",
    port: 3000,
    hot: true,
    inline: true, // 默认为true,在打包时会注入一段代码到最后的js中，用来监视页面的改动而自动刷新页面
    publicPath: `/dist/`, // 服务器打开虚拟路径
  },
  plugins: [new webpack.HotModuleReplacementPlugin()],
};
